package com.xc.controller;


import com.xc.exception.BaseException;
import com.xc.exception.BusinessException;
import com.xc.pojo.Result;
import com.xc.pojo.WhShelf;
import com.xc.pojo.input.WhShelfPageInput;
import com.xc.pojo.output.ShelfOutput;
import com.xc.service.IWhShelfService;
import com.xc.vo.ResultVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 架子表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-04-15
 */
@RestController
@RequestMapping("/wh-shelf")
@RequiredArgsConstructor
@Tag(name = "货架接口")
@Slf4j
public class WhShelfController {

    private final IWhShelfService shelfService;

    @Operation(summary = "mysql导出excel")
    @GetMapping("/export")
    public void export() {
        shelfService.export();
    }

    @Operation(summary = "excel导入mysql")
    @PostMapping("/importExcel")
    public void importExcel(@RequestParam("file") MultipartFile file) {
        System.out.println(file);
        System.out.println(file.toString());
        shelfService.importExcel(file);
    }

    @Operation(summary = "分页查询货架信息")
    @PostMapping("/page")
    public Result<List<ShelfOutput>> page(@RequestBody WhShelfPageInput pageInput) {
        log.info("pageInput：{}", pageInput);
        List<ShelfOutput> page = shelfService.getList(pageInput);
        page.forEach(System.out::println);
        return new Result<>();
    }

    @Operation(summary = "获取全部货架基本信息")
    @GetMapping("/get")
    public ResultVO<List<WhShelf>> get() {
        return ResultVO.success(shelfService.list());
    }

    @PostMapping("/getList")
    @Operation(summary = "模糊查询货架基本信息")
    public ResultVO<List<WhShelf>> getList(@RequestBody WhShelfPageInput pageInput) {
        return ResultVO.success(shelfService.getEntryList(pageInput));
    }

    @GetMapping("/testEx")
    @Operation(summary = "测试统一异常处理")
    public ResultVO testEx() {
        throw new BusinessException(9999, "货架不存在");
    }
}
